#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>

std::string getTimeStr()
{
    std::time_t t = std::time(nullptr);    // 获取当前时间点
    struct std::tm *local = localtime(&t); // 转换为本地时间
    if (local == nullptr)
        return "None";
    char cur_time[1024];
    snprintf(cur_time, sizeof(cur_time), "%d-%d-%d %d:%d:%d",
                local->tm_year + 1900, local->tm_mon + 1, local->tm_mday,
                local->tm_hour, local->tm_min, local->tm_sec);
    return cur_time;
}
enum
{
    INFO = 0,
    DEBUG,
    ERROR
};
static std::ostream &log(const std::string &level, const std::string &name, int line)
{
    std::string message = "[";
    message += level;
    message += "]";
    message += "[";
    message += name;
    message += "]";
    message += "[";
    message += std::to_string(line);
    message += "]";

    message += "[";
    message += getTimeStr();
    message += "]";

    std::cout << message;
    return std::cout;
}

#define LOG(level) log(#level, __FILE__, __LINE__)
